package com.api.gbhg.zengping.dao;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import weaver.conn.RecordSet;
import weaver.conn.RecordSetTrans;

import java.util.Map;

/**
 * @program: gbhg-oa
 * @description: this is a class
 * @author: Mr.zeng
 * @create: 2021-02-02 11:27
 **/
public class BudgetAdjustmentDao {
    public static final Logger LOGGER = LoggerFactory.getLogger("gbhg");

    /**
     * 查询主版本表归档的所有流程
     * @param map
     * @return
     */
    public RecordSet selectBylcztzList(Map<String,Object> map){
        String sql="select lcjlsqjlid,xmmin as xmmc,lcbj,fzr,sbdw,sbks,yszje from uf_jingfei_version where lcztz=3 and sfky=1";
        StringBuffer sb=new StringBuffer();
        sb.append(sql);
        // 查询条件  年度、单位、项目
        String sql1 = BudgetingListDao.getSql(map);
        sb.append(sql1);
        RecordSet rs=new RecordSet();
        // 分页
        int pageNum= (int) map.getOrDefault("pageNum",0);
        int pageSize= (int) map.getOrDefault("pageSize",0);
        if(pageNum==0&&pageSize==0){
        }else {
            pageNum=(pageNum-1)*pageSize;
            // 判断是mysql 还是sqlserver
            if("sqlserver".equals(rs.getDBType())){
                sb.append(" order by lcjlsqjlid offset "+pageNum+" rows fetch next "+pageSize+" rows only");
            }else if("mysql".equals(rs.getDBType())){
                sb.append(" LIMIT "+pageNum+","+pageSize+"");
            }
        }
        LOGGER.info("查询朱版本表归档的所有流程sql----->"+sql);
        rs.executeQuery(sb.toString());
        return rs;
    }

    /**
     * 查询主版本表归档的所有流程Count
     * @param map
     * @return
     */
    public RecordSet selectBylcztzCount(Map<String,Object> map){
        String sql="select count(1) num from uf_jingfei_version where lcztz=3 and sfky=1";
        StringBuffer sb=new StringBuffer();
        sb.append(sql);
        // 条件
        String sql1 = BudgetingListDao.getSql(map);
        sb.append(sql1);
        LOGGER.info("查询朱版本表归档的所有流程sql----->"+sql);
        RecordSet rs=new RecordSet();
        rs.executeQuery(sb.toString());
        return rs;
    }


    /**
     * 修改版本主表流程為不可用
     * @param requestId
     * @return
     */
    public boolean updateUfJFVersion(String requestId){
        RecordSetTrans rst=new RecordSetTrans();
        String sql="update uf_jingfei_version set sfky=0 where requestId="+requestId;
        try {
            rst.executeUpdate(sql);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }

}
